package chwgigs.swing.jdbc;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.BoxLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.JTextField;

public class J26_SungJukNewData extends JDialog {
	private JTextField name;
	private JTextField kor;
	private JTextField eng;
	private JTextField mat;

	public J26_SungJukNewData(JFrame P) {
		super(P);
		J26_SungJukService sjsrv = new J26_SungJukService();

		setSize(640, 480);
		setModalityType(ModalityType.DOCUMENT_MODAL);
		setTitle("J26_SungJukNewData");

		JPanel panel = new JPanel();
		getContentPane().add(panel, BorderLayout.CENTER);
		GridBagLayout gridBagLayout1 = new GridBagLayout();
		gridBagLayout1.columnWidths = new int[] { 25, 7, 117, 25, 25, 122, 0 };
		gridBagLayout1.rowHeights = new int[] { 25, 0, 25, 25, 25, 25, 0, 0, 0,
				0, 0, 0, 0, 0, 0, 0, 0, 0 };
		gridBagLayout1.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0,
				0.0, Double.MIN_VALUE };
		gridBagLayout1.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0,
				0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0,
				Double.MIN_VALUE };
		panel.setLayout(gridBagLayout1);

		JLabel titlelbl = new JLabel("이름과  성적을  입력   하세요");
		GridBagConstraints gbc_titlelbl = new GridBagConstraints();
		gbc_titlelbl.gridwidth = 2;
		gbc_titlelbl.insets = new Insets(0, 0, 5, 5);
		gbc_titlelbl.gridx = 3;
		gbc_titlelbl.gridy = 1;
		panel.add(titlelbl, gbc_titlelbl);

		JLabel namelbl = new JLabel("  이    름");
		GridBagConstraints gbc_namelbl = new GridBagConstraints();
		gbc_namelbl.anchor = GridBagConstraints.WEST;
		gbc_namelbl.insets = new Insets(0, 0, 5, 5);
		gbc_namelbl.gridx = 2;
		gbc_namelbl.gridy = 3;
		panel.add(namelbl, gbc_namelbl);

		JLabel korlbl = new JLabel("    국    어");
		GridBagConstraints gbc_korlbl = new GridBagConstraints();
		gbc_korlbl.anchor = GridBagConstraints.WEST;
		gbc_korlbl.insets = new Insets(0, 0, 5, 5);
		gbc_korlbl.gridx = 3;
		gbc_korlbl.gridy = 3;
		panel.add(korlbl, gbc_korlbl);

		JLabel englbl = new JLabel("     영   어");
		GridBagConstraints gbc_englbl = new GridBagConstraints();
		gbc_englbl.anchor = GridBagConstraints.WEST;
		gbc_englbl.insets = new Insets(0, 0, 5, 5);
		gbc_englbl.gridx = 4;
		gbc_englbl.gridy = 3;
		panel.add(englbl, gbc_englbl);

		JLabel matlbl = new JLabel("    수   학");
		GridBagConstraints gbc_matlbl = new GridBagConstraints();
		gbc_matlbl.anchor = GridBagConstraints.WEST;
		gbc_matlbl.insets = new Insets(0, 0, 5, 0);
		gbc_matlbl.gridx = 5;
		gbc_matlbl.gridy = 3;
		panel.add(matlbl, gbc_matlbl);

		name = new JTextField();
		GridBagConstraints gbc_name = new GridBagConstraints();
		gbc_name.anchor = GridBagConstraints.WEST;
		gbc_name.insets = new Insets(0, 0, 5, 5);
		gbc_name.gridx = 2;
		gbc_name.gridy = 5;
		panel.add(name, gbc_name);
		name.setColumns(10);

		kor = new JTextField();
		GridBagConstraints gbc_kor = new GridBagConstraints();
		gbc_kor.insets = new Insets(0, 0, 5, 5);
		gbc_kor.fill = GridBagConstraints.HORIZONTAL;
		gbc_kor.gridx = 3;
		gbc_kor.gridy = 5;
		panel.add(kor, gbc_kor);
		kor.setColumns(10);

		eng = new JTextField();
		GridBagConstraints gbc_eng = new GridBagConstraints();
		gbc_eng.insets = new Insets(0, 0, 5, 5);
		gbc_eng.fill = GridBagConstraints.HORIZONTAL;
		gbc_eng.gridx = 4;
		gbc_eng.gridy = 5;
		panel.add(eng, gbc_eng);
		eng.setColumns(10);

		mat = new JTextField();
		GridBagConstraints gbc_mat = new GridBagConstraints();
		gbc_mat.fill = GridBagConstraints.VERTICAL;
		gbc_mat.anchor = GridBagConstraints.WEST;
		gbc_mat.insets = new Insets(0, 0, 5, 0);
		gbc_mat.gridx = 5;
		gbc_mat.gridy = 5;
		panel.add(mat, gbc_mat);
		mat.setColumns(10);

		JLabel label = new JLabel("");
		GridBagConstraints gbc_label = new GridBagConstraints();
		gbc_label.insets = new Insets(0, 0, 5, 5);
		gbc_label.gridx = 3;
		gbc_label.gridy = 8;
		panel.add(label, gbc_label);

		J26_SungJukVO sj = new J26_SungJukVO();
		sj.setName(name.getName());
		sj.setKor(kor.getName());
		sj.setEng(eng.getName());
		sj.setMat(mat.getName());

		//

		if (sjsrv.createSungJuk(sj))
			JOptionPane.showMessageDialog(null, "입력완료");
		else
			JOptionPane.showMessageDialog(null, "입력실패");

		JButton btnNewButton = new JButton("확 인 ");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (name.getText().equals("") || kor.getText().equals("")
						|| eng.getText().equals("") || mat.getText().equals("")) {
					JOptionPane.showMessageDialog(null, "누락된 항목이 있네요", "오류발생",
							JOptionPane.ERROR_MESSAGE);
					return;
				}
				String nameval = name.getText();
				int korval = Integer.parseInt(kor.getText());
				int engval = Integer.parseInt(eng.getText());
				int matval = Integer.parseInt(mat.getText());
				String msg = nameval + "/" + korval + "/" + engval + "/"
						+ matval;
				JOptionPane.showMessageDialog(null, msg);
			}
		});
		
		{
			GridBagConstraints gbc_btnNewButton = new GridBagConstraints();
			gbc_btnNewButton.insets = new Insets(0, 0, 5, 5);
			gbc_btnNewButton.gridx = 4;
			gbc_btnNewButton.gridy = 9;
			panel.add(btnNewButton, gbc_btnNewButton);

			JButton button = new JButton("취소");
			button.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					name.setText("");
					kor.setText("");
					eng.setText("");
					mat.setText("");
				}
			});
			GridBagConstraints gbc_button = new GridBagConstraints();
			gbc_button.insets = new Insets(0, 0, 5, 0);
			gbc_button.gridx = 5;
			gbc_button.gridy = 9;
			panel.add(button, gbc_button);
		}

		setVisible(true);

	}//

}//
